package com.github.tetrisgame.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.github.tetrisgame.R;

public class BitmapUtils {
    public static BitmapUtils defaultUtils = new BitmapUtils();
    private Bitmap blueBitmap;
    private Bitmap orangeBitmap;
    private Bitmap purpleBitmap;
    private Bitmap yellowBitmap;
    private Bitmap greenBitmap;

    private BitmapUtils(){}

    //外部调用初始化方法，初始化对应的bitmap
    public void init(Context context){
        blueBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.blue);
        orangeBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.orange);
        purpleBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.purple);
        yellowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.yellow);
        greenBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.green);
    }

    //外部通过资源id获取对应的bitmap对象
    public Bitmap getBitmap(int resId){
        if (resId == R.drawable.blue){
            return blueBitmap;
        }else if (resId == R.drawable.orange){
            return orangeBitmap;
        } else if (resId == R.drawable.purple) {
            return purpleBitmap;
        } else if (resId == R.drawable.green) {
            return greenBitmap;
        }else{
            return yellowBitmap;
        }
    }
}
